module.exports = config =>{
    const jwt = require('jsonwebtoken')
    const assert = require('http-assert')
    
    return async (req,res,next)=>{
        const token = String(req.headers.authorization || " ").split(" ").pop()
        assert(token,401,"请登录用户")
        const {id} = jwt.verify(token,req.app.get('secret'))
        assert(id,401,"请登录用户")
        req.user = await require('../models/AdminUser').findById(id)
        assert(req.user,401,"请登录用户")
        next()
    }
}